<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="model.*,util.*,bll.*"%>
<%
	EventModel obj;
	Object temp = request.getAttribute("event");
	if (temp != null) {
		try {
			obj = (EventModel) temp;
		} catch (Exception ex) {
			obj = new EventModel();
		}
	} else {
		obj = new EventModel();
	}
	int idProject = obj.getIdProject();
	String projectName = CacheUtil.getProjectName(idProject);
	String projectUrl = "project.jsp?id=" + idProject;
	
	String idVenue=obj.getIdVenueToString();
	String VenueName=CacheUtil.getVenueName(obj.getIdVenue());
// 	String name=obj.getNameToString();
// 	if(session.getAttribute("name")!=null)
// 	{
// 		try
// 		{
// 		name=session.getAttribute("name").toString();
		
// 		}
// 		catch(Exception e)
// 		{}
// 	}		
// 	String code=obj.getCodeToString();
// 	if(session.getAttribute("code")!=null)
// 	{
// 		try
// 		{
// 		code=session.getAttribute("code").toString();
		
// 		}
// 		catch(Exception e)
// 		{}
// 	}		
// 	String description=obj.getDescriptionToString();
// 	if(session.getAttribute("description")!=null)
// 	{
// 		try
// 		{
// 			description=session.getAttribute("description").toString();
		
// 		}
// 		catch(Exception e)
// 		{}
// 	}						
// 	int idPlace=obj.getIdPlace();
// 	if(session.getAttribute("id_place")!=null)
// 	{
// 		try
// 		{
// 			String id_place=session.getAttribute("id_place").toString();
// 			idPlace=Integer.parseInt(id_place);
// 		}
// 		catch(Exception e)
// 		{}
// 	}	
// 	int idVenue=obj.getIdVenue();
// 	if(session.getAttribute("id_place")!=null)
// 	{
// 		idVenue=Integer.MIN_VALUE;
// 	}
	
	
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Event</title>

<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>


<link rel="stylesheet" href="css/inputForm.css" />

<script language="javascript" type="text/javascript">

	$(document).ready(pageLoaded);
	function pageLoaded()
	{
		turnOnNumbericInput();
		initTooltip();
	}

	var requiredInputs = [['name','name_required']];
	//var requiredInputs = [['name','name_required'], ['plan_start_date','plan_start_date_required'], ['plan_end_date','plan_end_date_required']
	//['real_start_date','real_start_date_required'], ['real_end_date','real_end_date_required']];
	//var intInputs = [];
	//var doubleInputs = [];
	//var dateInputs = [['plan_start_date','plan_start_date_invalid'],['plan_end_date','plan_end_date_invalid'],['real_start_date','real_start_date_invalid'],['real_end_date','real_end_date_invalid']];
	//var timeInputs = [];
	
	function checkInputs() {
		var valid = true;
	
		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
		//if (checkIntInputs(intInputs) == false) {
		//valid = false;
		//}
		//if (checkDoubleInputs(doubleInputs) == false) {
		//valid = false;
		//}
// 		if (checkDateInputsForCorrectedFormatOnly(dateInputs, dateFormat) == false) {
// 			valid = false;
// 		}
		//if (checkTimeInputs(timeInputs) == false) {
		//valid = false;
		//}
		
		// SPECIFIC VALIDATE CODE HERE		
		
		return valid;
	}
// 	function saveIdPlace()
// 	{
//   		document.getElementById("hidden_name").value=document.getElementById("name").value;
//   		document.getElementById("hidden_code").value=document.getElementById("code").value;
//   		document.getElementById("hidden_id_place").value=document.getElementById("id_place").value;
//   		document.getElementById("hidden_description").value=document.getElementById("description").value;
// 		document.idPlaceForm.submit();	
// 	}
function serializePlace()
{
	getCascadeDropdowList('#id_place','#id_venue','venue');
	
 	
}
</script>
</head>
<body onload="getCascadeDropdowList('#id_place','#id_venue','venue','<%=VenueName%>','<%=idVenue%>');">
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
<!-- 		<form id="idPlaceForm" name="idPlaceForm" action="event"  method="get"> -->
<!-- 			<input type="hidden" id="mode" name="mode" value="dependence" /> -->
<!-- 			<input type="hidden" id="hidden_name" name="hidden_name" value="" /> -->
<!-- 			<input type="hidden" id="hidden_code" name="hidden_code" value="" /> -->
<!-- 			<input type="hidden" id="hidden_id_place" name="hidden_id_place" value="" /> -->
<!-- 			<input type="hidden" id="hidden_description" name="hidden_description" value="" /> -->
<%-- 			<input type="hidden" id="hidden_idProject" name="hidden_idProject" value="<%=idProject%>" /> --%>
<%-- 			<input type="hidden" id="hidden_idEvent" name="hidden_idEvent" value="<%=obj.getId()%>" /> --%>
<!-- 		</form> -->
		<form id="inputForm" action="event?mode=update&id_project=<%=idProject%>" method="post" onSubmit="return checkInputs()" onreset="return confirm('Do you really want to reset the form?')">
			<table class="tblInput">
				<tr>
					<td colspan="3"><b>Project: <a id="link_project" name="link_project" href="<%=projectUrl%>"><%=projectName%></a> </b></td>
				</tr>
				<tr>
					<td class="inputHeader">Edit Event</td>
				</tr>
				<tr>
					<td style="padding-left: 400px; padding-right: 400px;">
						<table cellspacing="0px">
						<tr class="trField">
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput"><input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" value="<%=obj.getId()%>" title="Event ID. It's readonly."/></td>
							<td class="tdErrMsg"></td>
						<tr class="trField">
							<td class="tdFieldName">Name</td>
							<td class="tdFieldInput"><input class="inputText" type="text" id="name" name="name" maxlength="255" value="<%=obj.getNameToString()%>" title="Event name"  onblur="validateRequiredInput('name');"/></td>
							<td class="tdErrMsg">
								<span id="name_required" class="errMsg" style="display: none;" title="Name is a required field.">(!)</span> 
								<span id="name_error" class="errMsg"><%=obj.errMsgs.Name%></span>
							</td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Code</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="code" name="code" maxlength="20" value="<%=obj.getCodeToString() %>" title="Code of new event." />
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Place</td>
							<td class="tdFieldInput">
								<select id="id_place" name="id_place" class="hyjack" title="Choose a place for this event." onchange="serializePlace();">
								<%=HtmlUtil.<PlaceModel>genModelSelect(CacheUtil.getPlaceList(), null, obj.getIdPlace())%>
								</select>
								<input class="btnAdd" type="button" id="addNewPlace" value="" onclick="ajaxAddItem('#id_place', 'place', 'name', 'Please enter new place name!');" title="Click here to add new place."/>
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Venue</td>
							<td class="tdFieldInput">
								<select id="id_venue" name="id_venue" class="hyjack" title="Choose a venue for this event.">
									<option value="">---------------------</option>
<%-- 								<%=HtmlUtil.<VenueModel>genModelSelect(CacheUtil.getVenueList(idPlace), null,idVenue)%> --%>
									
								</select>
<!-- 								<input class="btnAdd" type="button" id="addNewVenue" value="" onclick="ajaxAddItem('#id_venue', 'venue', 'name', 'Please enter new venue name!');" title="Click here to add new venue."/> -->
							</td>
							<td class="tdErrMsg">
							</td>
						</tr>
						
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput"><textarea id="description" name="description" rows="5" class="inputTextarea" title="Description of the event"><%=obj.getDescriptionToString()%></textarea></td>
							<td class="tdErrMsg">
							</td>
						</tr>
						

						<tr class="trInputBottom">
							<td class="tdFieldName"></td>
							<td class="tdSubmit"><input class="btnSubmit" type="submit" value="Submit" title="Click to save above information."/></td>

						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<%
		String str = "eventList.jsp?embedded=true&idProject=" + obj.getIdProject();
	%>
	<jsp:include page="<%=str %>"></jsp:include>
	</div>
	<%
		session.removeAttribute("name");
		session.removeAttribute("code");
		session.removeAttribute("id_place");
		session.removeAttribute("description");
		session.removeAttribute("id_project_temp");
	%>
</body>
</html>